package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    ages := map[string]int{
        "alice":   31,
        "charlie": 34,
    }
    ages["bob"] = ages["bob"] + 1 // happy birthday!
    ages["alice"] = 32
    fmt.Println(ages["alice"]) // "32"
    fmt.Println(ages["bob"])
    ages["bob"]++
    fmt.Println(ages["bob"])

    for v := range ages {
        fmt.Printf("%v\n", v)
    }

    // True if equal is written incorrectly.
    fmt.Println(equal(map[string]int{"A": 0}, map[string]int{"B": 42}))

    seen := make(map[string]bool) // a set of strings
    input := bufio.NewScanner(os.Stdin)
    for input.Scan() {
        // 在这里终止键盘输入
        if err := input.Err(); err != nil {
            fmt.Fprintf(os.Stderr, "dedup: %v\n", err)
            os.Exit(1)
        }
        line := input.Text()
        if !seen[line] {
            seen[line] = true
            fmt.Println(line)
        }
    }
}

func equal(x, y map[string]int) bool {
    if len(x) != len(y) {
        return false
    }
    for k, xv := range x {
        // correct
        if yv, ok := y[k]; !ok || yv != xv {
            return false
        }
        // incorrect
        // if xv != y[k] {
        //     return false
        // }
    }
    return true
}
